package edu.unf.cen6940.dao;

import edu.unf.cen6940.domain.Facultyresearchtostudent;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Facultyresearchtostudent entities.
 * 
 */
@Repository("FacultyresearchtostudentDAO")
@Transactional
public class FacultyresearchtostudentDAOImpl extends AbstractJpaDao<Facultyresearchtostudent>
		implements FacultyresearchtostudentDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Facultyresearchtostudent.class }));

	/**
	 * EntityManager injected by Spring for persistence unit rms
	 *
	 */
	@PersistenceContext(unitName = "rms")
	private EntityManager entityManager;

	/**
	 * Instantiates a new FacultyresearchtostudentDAOImpl
	 *
	 */
	public FacultyresearchtostudentDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findFacultyresearchtostudentByFacultyResearchId
	 *
	 */
	@Transactional
	public Set<Facultyresearchtostudent> findFacultyresearchtostudentByFacultyResearchId(Integer facultyResearchId) throws DataAccessException {

		return findFacultyresearchtostudentByFacultyResearchId(facultyResearchId, -1, -1);
	}

	/**
	 * JPQL Query - findFacultyresearchtostudentByFacultyResearchId
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Facultyresearchtostudent> findFacultyresearchtostudentByFacultyResearchId(Integer facultyResearchId, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findFacultyresearchtostudentByFacultyResearchId", startResult, maxRows, facultyResearchId);
		return new LinkedHashSet<Facultyresearchtostudent>(query.getResultList());
	}

	/**
	 * JPQL Query - findFacultyresearchtostudentByFacultyId
	 *
	 */
	@Transactional
	public Set<Facultyresearchtostudent> findFacultyresearchtostudentByFacultyId(Integer facultyId) throws DataAccessException {

		return findFacultyresearchtostudentByFacultyId(facultyId, -1, -1);
	}

	/**
	 * JPQL Query - findFacultyresearchtostudentByFacultyId
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Facultyresearchtostudent> findFacultyresearchtostudentByFacultyId(Integer facultyId, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findFacultyresearchtostudentByFacultyId", startResult, maxRows, facultyId);
		return new LinkedHashSet<Facultyresearchtostudent>(query.getResultList());
	}

	/**
	 * JPQL Query - findFacultyresearchtostudentByPrimaryKey
	 *
	 */
	@Transactional
	public Facultyresearchtostudent findFacultyresearchtostudentByPrimaryKey(Integer facultyResearchId, Integer studentId, Integer facultyId) throws DataAccessException {

		return findFacultyresearchtostudentByPrimaryKey(facultyResearchId, studentId, facultyId, -1, -1);
	}

	/**
	 * JPQL Query - findFacultyresearchtostudentByPrimaryKey
	 *
	 */

	@Transactional
	public Facultyresearchtostudent findFacultyresearchtostudentByPrimaryKey(Integer facultyResearchId, Integer studentId, Integer facultyId, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findFacultyresearchtostudentByPrimaryKey", startResult, maxRows, facultyResearchId, studentId, facultyId);
			return (edu.unf.cen6940.domain.Facultyresearchtostudent) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findFacultyresearchtostudentByStudentId
	 *
	 */
	@Transactional
	public Set<Facultyresearchtostudent> findFacultyresearchtostudentByStudentId(Integer studentId) throws DataAccessException {

		return findFacultyresearchtostudentByStudentId(studentId, -1, -1);
	}

	/**
	 * JPQL Query - findFacultyresearchtostudentByStudentId
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Facultyresearchtostudent> findFacultyresearchtostudentByStudentId(Integer studentId, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findFacultyresearchtostudentByStudentId", startResult, maxRows, studentId);
		return new LinkedHashSet<Facultyresearchtostudent>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllFacultyresearchtostudents
	 *
	 */
	@Transactional
	public Set<Facultyresearchtostudent> findAllFacultyresearchtostudents() throws DataAccessException {

		return findAllFacultyresearchtostudents(-1, -1);
	}

	/**
	 * JPQL Query - findAllFacultyresearchtostudents
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Facultyresearchtostudent> findAllFacultyresearchtostudents(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllFacultyresearchtostudents", startResult, maxRows);
		return new LinkedHashSet<Facultyresearchtostudent>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Facultyresearchtostudent entity) {
		return true;
	}
}
